﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Home.Web.Data;
using Home.Web.Models.Resume;
using Home.Web.ViewModels;

namespace Home.Web.Controllers
{
    [RoutePrefix("api")]
    public class ResumeController : ApiController
    {
        private readonly ResumeDbContext _db = new ResumeDbContext();

        [Route("ResumesLookup")]
        public IQueryable<ResumeLookupView> GetResumesLookup()
        {
            var rl = _db.Resumes.Select(r => new ResumeLookupView {Id = r.Id, Name = r.Name});
            return rl;
        }

        [Route("Resumes")]
        public IQueryable<Resume> GetResumes()
        {
            return _db.Resumes;
        }

        [Route("Resume/{id:int}")]
        public HttpResponseMessage Get(int id)
        {
            var db = new ResumeDbContext();
            var resume = db.Resumes.Find(id);
            HttpResponseMessage msg = null;
            
            //msg = Request.CreateResponse<Resume[]>(HttpStatusCode.OK, resumes);
            msg = Request.CreateResponse<Resume>(HttpStatusCode.OK, resume);
            return msg;
        }
    }
}
